<template>
	<view>
		<pickerModule :picker="item" v-for="(item, index) in picker" :key="index" @pickerChange="pickerChange"></pickerModule>
		<baseForm :column.sync="column" @submitFun="submitFun" :submitStatus="submitDisable" :button="button"></baseForm>
		<progressBox :auditVos="auditVos" dictcode="dict_audit_status_car"></progressBox>
		<view class="buttons" v-if="getApprovalShow('applyStatus')">
			<button size="mini" class="middleButton" @click="pass('用车', itemData)">通过</button>
			<button size="mini" class="middleButton" @click="unpass('用车', itemData)">不通过</button>
		</view>
	</view>
</template>

<script>
import baseForm from '@/wxcomponents/form/form.vue';
import pickerModule from '@/wxcomponents/form/picker.vue';
import { format, dectList } from '@/libs/common.js';
import progressBox from '@/wxcomponents/commonLayout/progressLevel.vue';
import userMixins from '@/libs/userMixins.js';
import approvalMixins from '@/libs/approvalMixins.js';
import formMixins from '@/libs/formMixins.js';
export default {
	mixins: [userMixins, approvalMixins, formMixins],
	data() {
		return {
			itemData: '',
			button: {
				hide: true
			},
			picker: [
				{
					label: '申请车辆型号', //输入框title
					name: 'carType', //传值类型
					type: 'picker', //输入框类型
					disabled: true, //是否禁用
					required: true, //是否必须填写
					value: '', //输入框的值
					text: '请选择车辆型号',
					mode: 'selector', //picker的类型
					range: [] //picker的选项集合
				},
				{
					label: '申请车牌号',
					name: 'plateNumbers',
					type: 'picker',
					required: true,
					disabled: true,
					value: '',
					text: '请选择车牌号',
					mode: 'selector', //picker的类型
					range: [] //picker的选项集合
				}
			],
			carInfoList: [],
			column: [
				{
					label: '起始日期',
					value: '',
					required: true,
					name: 'startDate',
					type: 'picker',
					mode: 'date',
					text: '请选择'
				},
				{
					label: '起始时间',
					value: '',
					required: true,
					disabled: true,
					name: 'startTime',
					type: 'picker',
					mode: 'time',
					text: '请选择'
				},
				{
					label: '结束日期',
					value: '',
					required: true,
					name: 'endDate',
					type: 'picker',
					mode: 'date',
					text: '请选择'
				},
				{
					label: '结束时间',
					value: '',
					required: true,
					disabled: true,
					name: 'endTime',
					type: 'picker',
					mode: 'time',
					text: '请选择'
				},
				{
					label: '用车原因',
					name: 'applyReason',
					type: 'normalInput',
					disabled: true,
					required: false,
					value: ''
				},
				{
					label: '附件(最多上传三张)',
					type: 'upload',
					url: '/stu/common/uploadFile',
					docFileId: '',
					docFileUrl: '',
					attachmentVoListStr: '',
					limitSize: 3,
					disabled: true
				}
			],
			detailId: '',
			auditVos: ''
		};
	},
	async onLoad(option) {
		this.itemData = JSON.parse(option.data);
		this.getCarList();
		this.getDetail();
	},
	methods: {
		//查询可用车辆列表
		async getCarList() {
			let resp = await this.$http.post({
				url: '/oa/carConfig/list'
			});
			this.carInfoList = resp.result;
			if (resp.code == 0) {
				this.picker[0].range = resp.result.map(item => {
					return {
						id: item.id,
						name: item.carType
					};
				});
				this.picker[1].range = resp.result.map(item => {
					return {
						id: item.id,
						name: item.plateNumbers
					};
				});
			}
		},
		async getDetail() {
			let self = this;
			let caseMap = [
				{
					condition() {
						// 详情
						return self.itemData.detailType == 'detail';
					},
					async func() {
						let resp = await self.$http.get({
							url: `/oa/carApply/detail/${self.itemData.id}`
						});
						let startTime = resp.result.startTime;
						let endTime = resp.result.endTime;
						resp.result.startTime = startTime.split(' ')[1];
						resp.result.startDate = startTime.split(' ')[0];
						resp.result.endTime = endTime.split(' ')[1];
						resp.result.endDate = endTime.split(' ')[0];
						self.assignFormDataToViewModel(resp.result, self.column);
						self.auditVos = resp.result.audits;
						// 车辆型号、车牌号单独处理
						self.picker[0].text = resp.result.carType;
						self.picker[1].text = resp.result.plateNumbers;
					}
				},
				{
					condition() {
						// 审批
						return self.itemData.detailType == 'approval';
					},
					async func() {
						let resp = await self.$http.get({
							url: `/oa/carAudit/detail?id=${self.itemData.id}`
						});
						resp.result.startTime = resp.result.startTime.split(' ')[1];
						resp.result.startDate = resp.result.startTime.split(' ')[0];
						resp.result.endTime = resp.result.endTime.split(' ')[1];
						resp.result.endDate = resp.result.endTime.split(' ')[0];
						self.assignFormDataToViewModel(resp.result, self.column);
						self.auditVos = resp.result.audits;
						// 车辆型号、车牌号单独处理
						self.picker[0].text = resp.result.carType;
						self.picker[1].text = resp.result.plateNumbers;
					}
				}
			];
			let findOne = caseMap.filter(item => {
				return item.condition();
			})[0];
			if (!findOne) {
				alert(`getDetail方法出错`);
			}
			findOne.func();
		}
	},
	components: {
		baseForm,
		pickerModule,
		progressBox
	},
	watch: {}
};
</script>

<style></style>
